package com.ruoyi.admin.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.ruoyi.admin.domain.AlipayNameOrder;
import com.ruoyi.admin.mapper.AlipayNameOrderMapper;
import com.ruoyi.admin.service.IAlipayNameOrderService;
import java.util.Map;


/**
 * 姓名订单Service业务层处理
 * 
 * @author ouran
 * @date 2025-06-16
 */
@Service
public class AlipayNameOrderServiceImpl implements IAlipayNameOrderService 
{
    @Autowired
    private AlipayNameOrderMapper alipayNameOrderMapper;

    /**
     * 查询姓名订单
     * 
     * @param id 姓名订单主键
     * @return 姓名订单
     */
    @Override
    public AlipayNameOrder selectAlipayNameOrderById(Long id)
    {
        return alipayNameOrderMapper.selectAlipayNameOrderById(id);
    }

    /**
     * 查询姓名订单列表
     * 
     * @param alipayNameOrder 姓名订单
     * @return 姓名订单
     */
    @Override
    public List<AlipayNameOrder> selectAlipayNameOrderList(AlipayNameOrder alipayNameOrder)
    {
        return alipayNameOrderMapper.selectAlipayNameOrderList(alipayNameOrder);
    }

    /**
     * 新增姓名订单
     * 
     * @param alipayNameOrder 姓名订单
     * @return 结果
     */
    @Transactional
    @Override
    public int insertAlipayNameOrder(AlipayNameOrder alipayNameOrder)
    {
        alipayNameOrder.setCreateTime(DateUtils.getNowDate());
        int rows = alipayNameOrderMapper.insertAlipayNameOrder(alipayNameOrder);
        insertAlipayNameOrder(alipayNameOrder);
        return rows;
    }

    /**
     * 修改姓名订单
     * 
     * @param alipayNameOrder 姓名订单
     * @return 结果
     */
    @Transactional
    @Override
    public int updateAlipayNameOrder(AlipayNameOrder alipayNameOrder)
    {
        return alipayNameOrderMapper.updateAlipayNameOrder(alipayNameOrder);
    }

    /**
     * 批量删除姓名订单
     * 
     * @param ids 需要删除的姓名订单主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteAlipayNameOrderByIds(Long[] ids)
    {
        alipayNameOrderMapper.deleteAlipayNameOrderByOrderNos(ids);
        return alipayNameOrderMapper.deleteAlipayNameOrderByIds(ids);
    }

    /**
     * 删除姓名订单信息
     * 
     * @param id 姓名订单主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteAlipayNameOrderById(Long id)
    {
        alipayNameOrderMapper.deleteAlipayNameOrderByOrderNo(id);
        return alipayNameOrderMapper.deleteAlipayNameOrderById(id);
    }

    /**
     * 根据订单号插入姓名列表
     * 
     * @param params 包含订单号和姓名列表的参数
     * @return 结果
     */
    @Override
    public int insertNamesByOrderNo(Map<String, Object> params) {
        String orderNo = (String) params.get("orderNo");
        String namesStr = (String) params.get("namesStr");
        
        AlipayNameOrder order = new AlipayNameOrder();
        order.setOrderNo(orderNo);
        order.setNames(namesStr);
        
        return alipayNameOrderMapper.insertNamesByOrderNo(order);
    }
}
